package cn.ylyhappy.cainiao6

import android.os.Bundle
import android.util.Log
import com.google.android.material.bottomnavigation.BottomNavigationView
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import cn.ylyhappy.cainiao6.databinding.ActivityMainBinding
import cn.ylyhappy.cainiao6.databinding.FragmentHomeBinding
import cn.ylyhappy.netdemo.HttpApi
import cn.ylyhappy.netdemo.IHttpCallback
import cn.ylyhappy.netdemo.OkHttpApi

class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val navView: BottomNavigationView = binding.navView

        val navController = findNavController(R.id.nav_host_fragment_activity_main)
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        val appBarConfiguration = AppBarConfiguration(
            setOf(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications
            )
        )
        setupActionBarWithNavController(navController, appBarConfiguration)
        navView.setupWithNavController(navController)


        val map = mapOf(
            "key" to "free",
            "appid" to "0",
            "msg" to "我想和你做朋友"
        )

        val httpApi: HttpApi = OkHttpApi.getInstance()
        httpApi.get(map, "api.php", object : IHttpCallback{
            override fun onSuccess(data: Any) {
                Log.d("sss", "onSuccess: ")
            }

            override fun onFailed(error: Any) {
                Log.d("sss", "onError: ")
            }

        })

        httpApi.post(LoginReq(), "", object : IHttpCallback{
            override fun onSuccess(data: Any) {
                Log.d("sss", "onSucces22: $data")
            }

            override fun onFailed(error: Any) {
                Log.d("sss", "onSucces22: $error")
            }

        })
    }
    data class LoginReq (
        val mobi: String = "18648957777",
        val password: String = "cn5123456"
    )
}